/*
 * @Author: yangni 920556271@qq.com
 * @Date: 2024-03-20 15:48:51
 * @LastEditors: yangni 920556271@qq.com
 * @LastEditTime: 2024-04-29 11:36:27
 * @FilePath: /yt-devops/lib/model/amap_poi.dart
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import 'dart:ui';

import 'package:xbr_gaode_amap/base/amap_flutter_base.dart';
// import 'package:xbr_gaode_navi_amap/amap/base/amap_flutter_base.dart';

class AmapPoi {
  /// 纬度
  final double latitude;

  /// 经度
  final double longitude;
  String? neighborhood;
  String? building;
  String? province;
  String? provinceCode;
  String? countryCode;
  String? city;
  String? citycode;
  String? district;
  String? adcode;
  StreetNum? streetNumber;
  String? country;
  String? township;
  String? towncode;
  String? formattedAddress;
  String? name;

  AmapPoi(
      {required this.latitude,
      required this.longitude,
      this.neighborhood,
      this.building,
      this.province,
      this.provinceCode,
      this.countryCode,
      this.city,
      this.citycode,
      this.district,
      this.adcode,
      this.streetNumber,
      this.country,
      this.township,
      this.towncode,
      this.formattedAddress,
      this.name});

  factory AmapPoi.fromJson(Map<String, dynamic> json) => AmapPoi(
      latitude: json['latitude'],
      longitude: json['longitude'],
      neighborhood: json['neighborhood'] is String
          ? json['neighborhood']
          : json['neighborhood']['name'],
      building: json['building'] is String
          ? json['building']
          : json['building']['name'],
      province: json['province'],
      provinceCode: json['provinceCode'],
      countryCode: json['countryCode'],
      city: json['city'],
      citycode: json['citycode'],
      district: json['district'],
      adcode: json['adcode'],
      streetNumber:
          json['streetNumber'] != null ? StreetNum.fromJson(json) : null);
}

class StreetNum {
  String? direction;
  String? number;
  String? street;
  LatLng? location;
  num? distance;

  StreetNum(
      {this.direction, this.number, this.street, this.location, this.distance});

  StreetNum.fromJson(Map<String, dynamic> json) {
    direction = json['direction'];
    number = json['number'];
    street = json['street'];
    location =
        json['location'] != null ? LatLng.fromJson(json['location']) : null;
    distance = json['distance'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = Map<String, dynamic>();
    data['direction'] = this.direction;
    data['number'] = this.number;
    data['street'] = this.street;
    if (this.location != null) {
      data['location'] = this.location!.toJson();
    }
    data['distance'] = this.distance;
    return data;
  }
}

/// 经纬度坐标对象， 单位为度.
class LatLngModel {
  ///根据纬度[latitude]和经度[longitude]创建经纬度对象
  ///
  ///[latitude]取值范围 [-90.0,90.0].
  ///
  /// [latitude]取值范围 [-180.0,179.0]
  const LatLngModel(double latitude, double longitude)
      : latitude =
            (latitude < -90.0 ? -90.0 : (90.0 < latitude ? 90.0 : latitude)),
        longitude = (longitude + 180.0) % 360.0 - 180.0;

  /// 纬度
  final double latitude;

  /// 经度
  final double longitude;

  dynamic toJson() {
    return <double>[latitude, longitude];
  }

  /// 根据传入的经纬度数组 \[lat, lng\] 序列化一个LatLng对象.
  static LatLngModel? fromJson(dynamic json) {
    if (json == null) {
      return null;
    }
    return LatLngModel(json[0], json[1]);
  }

  @override
  String toString() => '$runtimeType($latitude, $longitude)';

  @override
  bool operator ==(Object o) {
    return o is LatLngModel &&
        o.latitude == latitude &&
        o.longitude == longitude;
  }

  @override
  int get hashCode => hashValues(latitude, longitude);
}
